package me.rjy.second.screen.demo

import android.app.Presentation
import android.content.Context
import android.os.Bundle
import android.view.Display
import android.view.WindowManager
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import me.rjy.second.screen.demo.databinding.LayoutSecondDisplayBinding

class SecondScreenPresentation(context: Context, display: Display) : Presentation(context, display) {
    private var mJob: Job? = null
    private lateinit var binding: LayoutSecondDisplayBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // 设置窗口属性，不获取焦点和触摸事件
        window?.addFlags(
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
        )
        binding = LayoutSecondDisplayBinding.inflate(layoutInflater)
        binding.pageTitle.text = "Presentation"
        setContentView(binding.root)

        var countDown = 30
        mJob = coroutineMain.launch {
            while (countDown-- > 0) {
                binding.tbCountDown.text = countDown.toString()
                delay(1000)
            }
            dismiss()
        }
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        mJob?.cancel()
    }
}